package com.lzyjkz.quick_admin.web.controller.role;

import com.lzyjkz.quick_components.entity.Response;
import com.lzyjkz.quick_components.utils.ValidatorUtils;
import com.lzyjkz.quick_system.entity.SysRole;
import com.lzyjkz.quick_system.service.SysRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/role")
@RestController
@RequiredArgsConstructor
@Tag(name = "角色管理")
public class SysRoleController {
    private final SysRoleService sysRoleService;

    @PostMapping("/add")
    @Operation(summary = "添加角色", description = "添加角色")
    public Response<String> add(@RequestBody SysRole role) throws Exception {
        ValidatorUtils.validateEntity(role);
        if (sysRoleService.lambdaQuery().eq(SysRole::getId, role.getId()).exists()) {
            return Response.fail("角色名已存在");
        }
        sysRoleService.save(role);
        return Response.success("添加成功");
    }
}
